var sign=0;
layui.use(['table','laypage','laydate'], function(){
			var table = layui.table;
		    var laydate=layui.laydate; 
	      var laypage = layui.laypage;
	   	 table.render({
			 elem: '#table',
			 url:contextPath+"/mis/searchXBPolicy",
			 page: true,
			 cellMinWidth: 80, //全局定义常规单元格的最小宽度，layui 2.2.1 新增
		     cols: [[
			      {
						title : '序号',
						width : 50,
						templet : function(d) {
							return d.LAY_TABLE_INDEX + 1
						}
					},
				      {field:'',  title: '旧保单号',
				    	  templet:function(d){
				              return d.lbCont.xbOldContno
				        }  
				      },
                 {field:'',  title: '新保单号',
                     templet:function(d){
                         return d.lbCont.xbNewContno
                     }
                 },
			      {field:'', width:80, title: '产品名称',
			    	  templet:function(d){
			    		  return d.proName
			        }
			      },
				 {field:'contNo', width:80, title: '保费',
			    	  templet:function(d){
			              return d.lCCont.premium
			        }
			      },
			      {field:'',  title: '签单时间',
			    	  templet:function(d){
			              return getTime(d.lCCont.signingDate)
			        }
			     },
			     {field:'',  title: '新保单生效时间',
			    	  templet:function(d){
			              return getTime(d.lCCont.startEffdate)
			        }
			     },
                 {field:'',  title: '新保单失效时间',
                     templet:function(d){
                         return getTime(d.lCCont.endEffDate)
                     }
                 },
					{field:'', width:120, title: '保费(元)',
			    	  templet:function(d){
			              return d.lCCont.premium
			        }
			      },

			    ]],
			    id:'testReload',
			    done: function(res, curr, count){ 
	                	var connt=res.data;
	                	var couut=0.00;
	                	for(var i=0;i<connt.length;i++){
	                		if(res.data[i].lCCont.status=="Y"){
	                			couut+=res.data[i].lCCont.premium*0.27;
	                			
	                		}
	                	}
	                	$("#fwf103").val(Math.round(couut*100)/100+"元");
	                	var tables = $("#table").next().find(".layui-table-box"); 
	                	tables.find("[data-field='123']").css("display","none"); //data-field的值就是你想要隐藏的某一列的field 
	             	    tables.find("[data-field='124']").css("display","none"); 
			    }
			  });
		
			 var $ = layui.$, active = {
					    reload: function(){
					    	var signingDate2= $('#signingDate2').val();
					      var startEffdate2= $('#startEffdate2').val();
					      if(signingDate2!=null&&signingDate2!=""){
					    	  signingDate2=  signingDate2+" 23:59:59";
					      }
					      if(startEffdate2!=null&&startEffdate2!=""){
					    	  startEffdate2=  startEffdate2+" 23:59:59";
					      }
					      if(!signingDate2){
					    	  var curDate = new Date()
					    	  var curYear = curDate.getFullYear()
					    	  var curMonth = curDate.getMonth()+1
					    	  var curDay = curDate.getDate()
					    	   signingDate2 = curYear + '-' + (curMonth < 10 ? '0' + curMonth : curMonth) + '-' + (curDay < 10 ? '0' + curDay : curDay)
					    	  }
					      if(!startEffdate2){
					    	  var curDate = new Date()
					    	  var curYear = curDate.getFullYear()
					    	  var curMonth = curDate.getMonth()+1
					    	  var curDay = curDate.getDate()
					    	   startEffdate2 = curYear + '-' + (curMonth < 10 ? '0' + curMonth : curMonth) + '-' + (curDay < 10 ? '0' + curDay : curDay)
					    	  }
					      //执行重载
					      table.reload('testReload', {
					        page: {
					          curr: 1 //重新从第 1 页开始
					        }
					        ,where: {
                                  xbNewContno:$('#xbNewContno').val(),
                                  xbOldContno:$('#xbOldContno').val(),
					        	signingDate1:$('#signingDate1').val(),
					        	signingDate2:signingDate2,
					        	productName:$('#productName').val(),
					        }
					      });
					    },
			 }


 $("#btn104").click(function(){
	window.location.href=contextPath+"/mis/exportPolicy?"+"sign=0"+"&"+$('#form').serialize();
    });	
 $("#btn103").click(function(){
 	var checked=$("#btn103").is(":checked");
 	var tables = $("#table").next().find(".layui-table-box"); 
 	if(checked){
 		$("#sign").val("1")
 	tables.find("[data-field='123']").css("display",""); //data-field的值就是你想要隐藏的某一列的field 
 	tables.find("[data-field='124']").css("display",""); 
     }else{
    	 $("#sign").val("0")
     tables.find("[data-field='123']").css("display","none"); //data-field的值就是你想要隐藏的某一列的field 
	    tables.find("[data-field='124']").css("display","none"); 
     }
 });
//时间戳格式化
 function add0(m){return m<10?'0'+m:m }
 function getTime(dateStr)
 {
 	var time = new Date(dateStr);
 	var y = time.getFullYear();
 	var m = time.getMonth()+1;
 	var d = time.getDate();
 	return y+'-'+add0(m)+'-'+add0(d);
 }
 $('#selectTable').on('click', function(){
		var type = $(this).data('type');
		active[type] ? active[type].call(this) : '';
	});	 
 
 $ = layui.jquery;
 //日期范围
 laydate.render({
   elem: '#signingDate1',
   done: function(value, date, endDate){
	    var min = $.extend({},date)
	    	, max = $.extend({},date);
	    min.month = min.month-1;//不清楚为什么在设置月份的时候必须要-1，不清楚作者是否有意为之
	    max.month = max.month-1;
	    max.date = max.date+180;

	    endIns1.config.min = min;
	    endIns1.config.max = max;
	    console.info(endIns1);
	    $(endIns1.config.elem).focus().val('');
	  }
 });
 var endIns1 = laydate.render({
	elem: '#signingDate2'
 });
 
 laydate.render({
	elem: '#startEffdate1',
	done: function(value, date, endDate){
	    var min = $.extend({},date)
	    	, max = $.extend({},date);
	    min.month = min.month-1;//不清楚为什么在设置月份的时候必须要-1，不清楚作者是否有意为之
	    max.month = max.month-1;
	    max.date = max.date+180;

	    endIns2.config.min = min;
	    endIns2.config.max = max;
	    console.info(endIns2);
	    $(endIns2.config.elem).focus().val('');
	  }
});
 var endIns2 = laydate.render({
  elem: '#startEffdate2'
 });
			});
